<?php

/*
EDIT:
Why is that needed? This file shouldn't be accessed directly
You can do a POST to admin-post.php and hook an action like:
	add_action('admin_post', 'my_function_on_post');

it can be <form action"<?php echo admin_url('admin-post.php'); ... etc."
(see wp-admin/admin-post.php can add several actions if needed).

Can also intercept it with somethoing like this:
	if ( isset($_POST['theme_buildpress']) && ($_POST['theme_buildpress'] == 1) )
(has to always be in the submitted form)
*/

define('WP_ADMIN', true);
// EDIT: this is needed to load the admin if not using the above method
if ( defined('ABSPATH') )
	require_once(ABSPATH . 'wp-load.php');
else
	require_once('../../../../../wp-load.php'); // this will fail when /wp-content has been moved

require_once(ABSPATH . 'wp-admin/includes/admin.php');

nocache_headers();
// end EDIT

do_action('admin_init');

// EDIT: cap check
if ( !current_user_can('edit_themes') )
	die('-1');

if ( isset($_POST['theme_buildpress']) && ($_POST['theme_buildpress'] == 1) ) {
	$theme_name = $_POST['theme_name']; // EDIT: stripslashes()?
} else {
	die('-1');
}

if ( isset($_GET['edit']) ) {
		global $b;
		$theme_info = $b->getTheme($_GET['edit']); // EDIT: stripslashes()?
		$theme_name = $theme_info['themename'];
		
		$bannertop = ($theme_info['bannertop'] != "")? $theme_info['bannertop'] : '0';
		$bannerbottom = ($theme_info['bannerbottom'] != "")? $theme_info['bannerbottom'] : '0';
		
		$edit_div = '<div id="edit_details" title="edit_theme" style="display:none">';
		$edit_div .= '<div class="which_doc">'.$theme_info['docstyle'].'</div>' . "\n";
		$edit_div .= '<div class="splitBody-0">'.$theme_info['body'].'</div>'. "\n";
		$edit_div .= '<div class="colorscheme">'.$theme_info['colorscheme'].'</div>'. "\n";
		$edit_div .= '<div class="sidebar_top">'.$bannertop.'</div>'. "\n";
		$edit_div .= '<div class="sidebar_bottom">'.$bannerbottom.'</div>'. "\n";
		$edit_div .= '<div class="header_css">'.$theme_info['stylesheets'][0].'</div>'. "\n";
		$edit_div .= '<div class="footer_css">'.$theme_info['stylesheets'][3].'</div>'. "\n";
		$edit_div .= '<div class="body_css">'.$theme_info['stylesheets'][1].'</div>'. "\n";
		$edit_div .= '<div class="widget_css">'.$theme_info['stylesheets'][2].'</div>'. "\n";
		$edit_div .= '</div>';
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BuildPress &raquo; <?php echo $theme_name; ?> </title>

<link rel="stylesheet" type="text/css" href="css/colorpicker.css" />
<link rel="stylesheet" type="text/css" href="css/south-street/jquery-ui-1.7.1.custom.css" />
<link rel="stylesheet" type="text/css" href="<?php echo BP_URL; ?>/engine/includes/css/reset-fonts-grids.css" />
<link rel="stylesheet" type="text/css" href="css/builder.css" />
<link rel="stylesheet" type="text/css" href="css/boxy.css" />
<link rel="stylesheet" type="text/css" href="css/jcrop.css" />

<link rel="stylesheet" href="<?php echo BP_REPO_URL ?>/base.css" type="text/css" media="screen" />

<!-- new ones -->
<?php writeCSS("content","link"); ?>
<?php writeCSS("widget","link"); ?>
<?php writeCSS("header","link"); ?>
<?php writeCSS("footer","link"); ?>

<link rel="stylesheet" type="text/css" href="http://localhost/wp28/wp-content/themes/buildpress/engine/includes/css/colors/default.php" media="screen" />


<script type="text/javascript">
var ajaxURL = "<?php echo admin_url('admin-ajax.php'); ?>";
var BP_URL = "<?php bloginfo('stylesheet_directory'); ?>";
var BP_ADMIN_URL = "<?php

// EDIT: cannot trust the referer... need to use another way for this
//echo $_SERVER['HTTP_REFERER'];

// perhaps this will be better
echo admin_url('themes.php?page=buildpress.admin.page.php');


?>";
var themename = "<?php echo $theme_name; ?>";
var nonce = "<?php echo js_escape( wp_create_nonce( 'ajaxnonce' ) ); ?>";
</script>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.Jcrop.min.js"></script>
<script type="text/javascript" src="js/ajaxfileupload.js"></script>
<script type="text/javascript" src="js/jquery.boxy.js"></script>
<script type="text/javascript" src="js/equalheights.js"></script>
<script type="text/javascript" src="js/colorpicker.js"></script>
<script type="text/javascript" src="js/builder.js"></script>
</head>
<body>

<div class="main-page">
<div id="hd">

</div>

<div id="bd"> 
	<div id="yui-main">
		<div class="yui-b" id="page-0">
        
        </div>        
    </div>    
    </div>
    
<div id="ft">
</div>

</div>

<?php echo ($edit_div); ?>


<div style="height:35px"></div>

<div id="custom_header_box" style="display:none;">
		<div id="upload_form">
            <form id="form1" action="" method="post" enctype="multipart/form-data">
            <input type="file" name="file" id="file" />
            <input type="button" id="buttonUpload" value="Upload Image" />
            </form>
		</div>
        
        <div id="crop_form" style="display:none">
            <form action="" method="post" id="crop_details">
            <input type="hidden" id="x" name="x" />
            <input type="hidden" id="y" name="y" />
            <input type="hidden" id="w" name="w" />
            <input type="hidden" id="h" name="h" />
            <input type="hidden" id="fname" name="fname"  />
            <input type="button" value="Crop Image"/>
            </form>
        </div>
</div>

<div id="custom_color_scheme_creator" style="display:none">
<form>
<label>
<div id="cc_0" class="colorSelector">
<input type="hidden" name="cc_0" value="000000" /><div class="color_thumb" style="background-color: #000000;"></div>
</div>                
</label>
<label>
<div id="cc_1" class="colorSelector">
<input type="hidden" name="cc_1" value="000000" /><div class="color_thumb" style="background-color: #000000;"></div>
</div>                
</label>
<label>
<div id="cc_2" class="colorSelector">
<input type="hidden" name="cc_2" value="000000" /><div class="color_thumb" style="background-color: #000000;"></div>
</div>                
</label>
<label>
<div id="cc_3" class="colorSelector">
<input type="hidden" name="cc_3" value="000000" /><div class="color_thumb" style="background-color: #000000;"></div>
</div>                
</label>
<label>
<div id="cc_4" class="colorSelector">
<input type="hidden" name="cc_4" value="000000" /><div class="color_thumb" style="background-color: #000000;"></div>
</div>                
</label>
<label>
<div id="cc_5" class="colorSelector">
<input type="hidden" name="cc_5" value="000000" /><div class="color_thumb" style="background-color: #000000;"></div>
</div>                
</label>
<p>
<input type="button" id="custom_color_scheme_button" value="Add This Scheme" />
</p>
</form>
</div>

<div id="builder">
<div id="buider_wrapper">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tbody>
<td width="20%" align="left"><strong>Buildpress &raquo; <?php echo $theme_name; ?></strong></td>
<td width="12%">
<button type="button" class="builder_button" title="page_layout" >Page Layout</button>
<div id="page_layout">
<h1 class="builder_title">Page Layout</h1>
<div style="margin:10px">
<form class="grids" id="panel-form-1" name="panel-form-1" >
<?php if(isset($_GET['edit'])) { ?>
<input type="hidden" name="theme_id" id="theme_id" value="<?php echo $_GET['edit']; ?>" />
<?php } ?>
 <fieldset>
            <legend>Page Width</legend>
            <select id="which_doc" name="which_doc">
                <option value="doc" selected="selected">750px</option>
                <option value="doc2">950px</option>
                <option value="doc3">100%</option>
            </select>
            <p>Select the overall size of the Theme</p>
        </fieldset>        
        <fieldset>
        <legend>Layout</legend>

			<div class="first-row">

				<label>
                	<select id="splitBody-0" name="splitBody-0"  class="colvalue">
                    	<option value="1">1 Column (100)</option>
						<option value="7" selected="selected">2 Column (66/33)</option>
						<option value="8">2 Column (33/66)</option>
						<option value="9">2 Column (75/25)</option>
						<option value="10">2 Column (25/75)</option>
                        <option value="3">3 Column (25/50/25)</option>
						<option value="5">3 Column (50/25/25)</option>
						<option value="6">3 Column (25/25/50)</option>
					</select>
				</label>
                <p>Select the Theme Structure.</p>
			</div>
</fieldset>

<fieldset>
            <legend>Banners</legend>	
			<div>
				<input type="checkbox" name="sidebar_top" id="sidebar_top" value="sidebartop" class="sidebar-access"><label for="sidebartop">&nbsp;&nbsp;Banner below Header</label>
			</div>
			<div>
				<input type="checkbox" name="sidebar_bottom" id="sidebar_bottom" value="sidebarbottom"  class="sidebar-access"><label for="sidebarbottom">&nbsp;&nbsp;Banner above Footer</label>
			</div>
</fieldset>
</form>
</div>
</div>
</td>
<td width="12%">
<button type="button" class="builder_button" title="page_design" >Page Design</button>
<div id="page_design">
<h1 class="builder_title">Page Design</h1>
<div style="margin:10px;">
<form class="grids" id="panel-form-2" name="panel-form-2" >
<p>The section contains CSS styles for the following parts of a theme. You can create your own CSS styles as well :)</p>
<fieldset>
            <legend>Header</legend>
            <select id="header_css" name="header_css">
            	<?php writeCSS('header');	?>
            </select>
        </fieldset>
        
        <fieldset>
            <legend>Footer</legend>
            <select id="footer_css" name="footer_css">
            	<?php writeCSS('footer');	?>
            </select>
        </fieldset>
        
		<fieldset>
            <legend>Body</legend>
            <select id="body_css" name="body_css">
            	<?php writeCSS('content');	?>
            </select>
        </fieldset>
        
        <fieldset>
            <legend>Widget Style</legend>
            <select id="widget_css" name="widget_css">
            	<?php writeCSS('widget');	?>
            </select>
        </fieldset>
        <!--
        <fieldset>
            <legend>Color Scheme</legend>
            <div id="colorscheme-css" class="colorSelector"><input type="hidden" name="colorscheme-css" value="000000" /><div style="background-color: #000000;"></div></div>
        </fieldset>
        
        <fieldset>
        	<legend>Custom Header</legend>
            <input type="button" id="custom_header_invoke" name="custom_header_invoke" value="Upload" />
        </fieldset>
        -->
</form>
</div>
</div>
</td>

<td width="12%">
<button type="button" class="builder_button" title="page_colors" >Page Colors</button>
<div id="page_colors">
    <h1 class="builder_title">Page Colors</h1>
    <div style="margin:10px; color:#222;">
    
    <button id="custom_color_scheme_link" class="custom_color_button" type="button">Create Color Scheme</button>
    <form class="grids" id="panel-form-3" name="panel-form-3" >
    <p>Select any Color Scheme for your theme or create your own Color Scheme.</p>
    <fieldset>
    <?php
    global $b;
    ?>
    <?php $colorschemes = $b->getColors();
			$checked = 'checked="checked"';
			
			if(!$colorschemes) {
				$b->saveColors("#eeead9","#261c13","#f44365","#fff","#4086AA","#91C3DC");
				$b->saveColors("#ffffff","#91C3DC","#4086AA","#fff","#0071bb","#f44365");
				$b->saveColors("#C5EFFD","#006295","#BD2031","#fff","#231F20","#BD2031");
				$b->saveColors("#FDE8D7","#B96A9A","#9CC089","#fff","#231F20","#9CC089");
			}
		foreach($colorschemes as $key=>$c) : ?>
            <div class="color_scheme_thumb" id="color-scheme-<?php echo $key; ?>">
            <div class="color_thumb" style="background-color:<?php echo $c[0]; ?>"></div>
            <div class="color_thumb" style="background-color:<?php echo $c[1]; ?>"></div>
            <div class="color_thumb" style="background-color:<?php echo $c[2]; ?>"></div>
            <div class="color_thumb" style="background-color:<?php echo $c[3]; ?>"></div>
            <div class="color_thumb" style="background-color:<?php echo $c[4]; ?>"></div>
            <div class="color_thumb" style="margin-right:20px; background-color:<?php echo $c[5]; ?>">
            </div>
            <input type="radio" id="colorscheme[]" name="colorscheme" <?php echo $checked; ?>  value="<?php echo $key; ?>" title="<?php echo implode(",", $c); ?>" />&nbsp;<a href="javascript:void(0);" class="delete_color_scheme">[x]</a>
            <div style="clear:both"></div>
            </div>
    <?php $checked = ""; endforeach; ?>
    </fieldset>
    </form>
	</div>
</div>
</td>

<td width="15%">
<button type="button" class="builder_button" title="page_props" >Page Typography</button>
<div id="page_props">

<h1 class="builder_title">Page Typography</h1>
<div style="margin:10px">
<form class="grids" id="panel-form-4" name="panel-form-4" >
<!--
<fieldset>
<legend>Header 1</legend>
	<div class="first-row">
				<label>Font
					<select id="FontSelect-h1" name="FontSelect-h1" class="FontSelection">
                    	<option value="arial,helvetica,clean,sans-serif" selected="selected">Arial</option>
                    	<option value="Verdana">Verdana</option>
                        <option value='Times'>Times</option>
                        <option value="Georgia">Georgia</option>
                        <option value='Tahoma, Geneva, sans-serif'>Tahoma</option>
                        <option value='"Trebuchet MS", Arial, Helvetica, sans-serif'>Trebuchet</option>
                        <option value='Courier'>Courier</option>
					</select>
				</label>               
                <label>Color
                <div id="ColorSelect-h1" class="colorSelector"><input type="hidden" name="ColorSelect-h1" value="000000" /><div style="background-color: #000000;"></div></div>
                
				</label>
                 <label>Size
					<input type="text" id="SizeSelect-h1" name="SizeSelect-h1" class="SizeSelect" style="width:30px;" maxlength="3" value="300" />%<div id="SizeSelectSlider-h1" class="SizeSelectSlider"></div>
				</label>
		</div>
</fieldset>
-->
<fieldset>
<legend>Header 2</legend> 
        	<div class="first-row">
				<label>Font
					<select id="FontSelect-h2" name="FontSelect-h2" class="FontSelection">
                    	<option value="arial,helvetica,clean,sans-serif" selected="selected">Arial</option>
                    	<option value="Verdana">Verdana</option>
                        <option value='Times'>Times</option>
                        <option value="Georgia">Georgia</option>
                        <option value='Tahoma, Geneva, sans-serif'>Tahoma</option>
                        <option value='"Trebuchet MS", Arial, Helvetica, sans-serif'>Trebuchet</option>
                        <option value='Courier'>Courier</option>
					</select>
				</label>
                 <label>Color
                  <div id="ColorSelect-h2" class="colorSelector"><input type="hidden" name="ColorSelect-h2" value="000000" /><div style="background-color: #000000;"></div></div>
                  
				</label>
                <label>Size
					<input type="text" id="SizeSelect-h2" name="SizeSelect-h2" class="SizeSelect" style="width:30px;" maxlength="3" value="175" />%<div id="SizeSelectSlider-h2" class="SizeSelectSlider"></div>
				</label>
		</div>
</fieldset>     
<fieldset>
<legend>Header 3</legend> 
        	<div class="first-row">
				<label>Font
					<select id="FontSelect-h3" name="FontSelect-h3" class="FontSelection">
	                    <option value="arial,helvetica,clean,sans-serif" selected="selected">Arial</option>
                    	<option value="Verdana">Verdana</option>
                        <option value='Times'>Times</option>
                        <option value="Georgia">Georgia</option>
                        <option value='Tahoma, Geneva, sans-serif'>Tahoma</option>
                        <option value='"Trebuchet MS", Arial, Helvetica, sans-serif'>Trebuchet</option>
                        <option value='Courier'>Courier</option>
					</select>
				</label>
                 <label>Color
				<div id="ColorSelect-h3" class="colorSelector"><input type="hidden" name="ColorSelect-h3" value="000000" /><div style="background-color: #000000;"></div></div>
                
				</label>
                <label>Size
					<input type="text" id="SizeSelect-h3" name="SizeSelect-h3" class="SizeSelect" style="width:30px;" maxlength="3" value="150" />%<div id="SizeSelectSlider-h3" class="SizeSelectSlider"></div>
				</label>
		</div>
</fieldset>

<fieldset>
<legend>Text</legend> 
        	<div class="first-row">
				<label>Font
					<select id="FontSelect-p" name="FontSelect-p" class="FontSelection">
	                    <option value="arial,helvetica,clean,sans-serif" selected="selected">Arial</option>
                    	<option value="Verdana">Verdana</option>
                        <option value='Times'>Times</option>
                        <option value="Georgia">Georgia</option>
                        <option value='Tahoma, Geneva, sans-serif'>Tahoma</option>
                        <option value='"Trebuchet MS", Arial, Helvetica, sans-serif'>Trebuchet</option>
                        <option value='Courier'>Courier</option>
					</select>
				</label>
                 <label>Color
                 <div id="ColorSelect-p" class="colorSelector"><input type="hidden" name="ColorSelect-p" value="000000" /><div style="background-color: #000000;"></div></div>
                 
               	</label>
                <label>Size
					<input type="text" id="SizeSelect-p" name="SizeSelect-p" class="SizeSelect" style="width:30px;" maxlength="3" value="100" />%<div id="SizeSelectSlider-p" class="SizeSelectSlider"></div>
				</label>
		</div>
</fieldset>
</form>

</div>
</div>
</td>

<td width="9%">
</td>
<td width="20%">
<button type="button" class="builder_button" style="background-color:#FF7900" id="button-export" title="save_buildpress" name="button-export" >Save and Export &raquo;</button>
</td>
</tbody>

</table>
</div>
</div>
</body>
</html>
